package com.example.myapplication;


import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private Button button;
    private int clickCount = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 获取UI组件引用
        textView = findViewById(R.id.textView);
        button = findViewById(R.id.button);

        // 设置按钮点击事件
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickCount++;
                updateText();
            }
        });

        // 初始化显示
        updateText();
    }

    private void updateText() {
        String message = "你点击了按钮 " + clickCount + " 次";
        textView.setText(message);
    }
}